package tests;

import estructuras.EmptyQueueException;
import estructuras.FullQueueException;
import estructuras.QueueUsingCircularList;
import junit.framework.TestCase;



/**
 * CC2003 - Worksheet 3 - Queues in a Bank
 * 
 * For the course CC2003 - Algorithms and Data Structures of UVG (Universidad del Valle de Guatemala, http://uvg.edu.gt)
 * 
 * 
 * SVN Repository of my course projects: http://cc2003.svn.sourceforge.net/viewvc/cc2003/
 * 
 * 
 * Copyright (C) 2009 Carlos Lopez Camey
 * visit me at http://kmels.net or write me at c.lopez@kmels.net
 * 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 * @author kmel
 *
 */
public class QueueUsingCircularListTest extends TestCase {
	QueueUsingCircularList<Integer> queue = new QueueUsingCircularList();
	
	/**
	 * @param name
	 */
	public QueueUsingCircularListTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test method for {@link BankQueueUsingCircularList#add(java.lang.Object)}.
	 * @throws FullQueueException 
	 * @throws EmptyQueueException 
	 */
	public void testAdd() throws FullQueueException, EmptyQueueException {
		queue.add(5);
		assertTrue(queue.getNelements()==1);
		assertTrue(queue.peek()==5);
		queue.add(4);
		assertTrue(queue.peek()==5);
		queue.add(3);
		queue.add(2);
		queue.add(1);
		assertTrue(queue.getNelements()==5);
		assertTrue(queue.peek()==5);
	}

	/**
	 * Test method for {@link BankQueueUsingCircularList#remove()}.
	 * @throws FullQueueException 
	 * @throws EmptyQueueException 
	 */
	public void testRemove() throws FullQueueException, EmptyQueueException {
		assertTrue(queue.getNelements()==0);
		queue.add(8);
		assertTrue(queue.peek() == 8);
		queue.add(3);
		queue.add(2);
		assertTrue(queue.getNelements()==3);
		int dequeded = queue.remove();
		assertTrue(dequeded == 8);
		assertTrue(queue.getNelements()==2);
		assertTrue(queue.remove() == 3);
		assertTrue(queue.remove() == 2);
		assertTrue(queue.isEmpty());
		queue.add(1);
		queue.add(2);
		queue.add(3);
		queue.add(4);
		queue.add(5);
		queue.add(6);
		assertTrue(queue.getNelements()==6);
		for (int i=1; i<=6; i++){
			assertTrue(queue.remove() == i);
		}
		
		assertTrue(queue.getNelements()==0);
		assertTrue(queue.isEmpty());
	}

	/**
	 * Test method for {@link BankQueueUsingCircularList#peek()}.
	 * @throws FullQueueException 
	 * @throws EmptyQueueException 
	 */
	public void testPeek() throws FullQueueException, EmptyQueueException {
		queue.add(3);
		assertTrue(queue.peek()==3);
	}

	/**
	 * Test method for {@link BankQueueUsingCircularList#BankQueueUsingCircularList()}.
	 */
	public void testBankQueueUsingCircularList() {
		QueueUsingCircularList<Integer> queue = new QueueUsingCircularList();
		
		assertTrue(queue.getTail().next == null);
		assertTrue(queue.getNelements() == 0);
	}
	

	/**
	 * Test method for {@link BankQueue#isFull()}.
	 * @throws FullQueueException 
	 */
	public void testIsFull() throws FullQueueException {
		for (int i = 1; i<= 10; i++)
			queue.add(i);
		
		assertTrue(queue.isFull());
	}

	/**
	 * Test method for {@link BankQueue#isEmpty()}.
	 */
	public void testIsEmpty() {
		assertTrue(queue.isEmpty());
	}


}
